package com.kevin.sharding.demo.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @version UserDao.java v2.0
 * @description:
 * @author: wenze
 * @create: 2020/9/3 21:50
 **/
@Mapper
@Component
public interface UserDao {

    @Insert("insert into t_user(user_id,full_name) values(#{userId},#{fullName})")
    void insertUser(@Param("userId") Long userId, @Param("fullName") String fullName);

    @Select("<script>" +
            "select * from t_user where user_id in" +
            "<foreach collection='userIds' item='userId' open='(' close=')' separator=','>" +
            "#{userId}" +
            "</foreach>" +
            "</script>"
    )
    List<Map> queryUserByIds(@Param("userIds") List<Long> userIds);

    @Select("<script>" +
            "select" +
            "*" +
            "\t" +
            "from t_user t,t_dict b where t.user_type = b.code and user_id in" +
            "<foreach collection='userIds' item='userId' open='(' close=')' separator=','>" +
            "#{userId}" +
            "</foreach>" +
            "</script>"
    )
    List<Map> unionQuery(@Param("userIds") List<Long> userIds);
}
